(function () {
    var io = ppt.io;
    
    var BossHP = (function (_super) {
        function BossHP(totalHP) {
            BossHP.super(this);

            this.BG = null;
            this.bar = null;
            this.totalHP = totalHP;

            this.init();
        }
        Laya.class(BossHP, "", _super);
        var _proto = BossHP.prototype;
        _proto.destroy = function () {
            _super.prototype.destroy.call(this, true);

            this.BG = null;
            this.bar = null;
            this.totalHP = null;
        }

        _proto.init = function () {
            this.size(405, 18);

            var BG = new Laya.Image("res/game/ui/boss_hp_bg.png");
                BG.pos(-9, -14);
                
            var bar = new Laya.Image("res/game/ui/boss_hp_bar.png");
                bar.sizeGrid = "9,10,9,10";
                bar.size(this.width, this.height);

            this.BG = BG;
            this.bar = bar;
            this.addChildren(BG, bar);
        }

        _proto.update = function (value) {
            var width = value / this.totalHP * this.width;
            Laya.Tween.to(this.bar, {width : width}, 300);
        }
        return BossHP;
    })(Laya.Sprite);

    var Avatar = (function (_super) {
        function Avatar(skinId) {
            Avatar.super(this);

            this.cover = null;
            this.avatar = null;
            this.skinId = skinId;

            this.init();
        }
        Laya.class(Avatar, "", _super);
        var _proto = Avatar.prototype;
        _proto.destroy = function () {
            _super.prototype.destroy.call(this, true);

            this.cover = null;
            this.avatar = null;
            this.skinId = null;
        }

        _proto.init = function () {
            this.size(48, 48);
            
            var cover = new Laya.Image("res/game/ui/boss_avatar_frame.png");
                cover.centerX = 0;
                cover.y = -11;

            var avatar = new Laya.Image("other/monster_avatar/" + this.skinId + ".png");
            
            this.cover = cover;
            this.avatar = avatar;
            
            this.addChildren(avatar, cover);
        }
        return Avatar;
    })(Laya.Box);

    (function (_super) {
        function MonsterInfo(data) {
            MonsterInfo.super(this);

            this.avatar = null;
            this.HP = null;

            this.init(data);
        }
        Laya.class(MonsterInfo, "Game.MonsterInfo", _super);
        var _proto = MonsterInfo.prototype;
        _proto.destroy = function () {
            _super.prototype.destroy.call(this, true);

            io.unregister("monster::hit", this.update);

            this.avatar = null;
            this.HP = null;
        }

        _proto.init = function (data) {
            io.register("monster::hit", this, this.update);
            
            var HP = new BossHP(data.hp);

            var avatar = new Avatar(data.skinId);
                avatar.pos(-44, -18);

            this.HP = HP;
            this.avatar = avatar;
            this.addChildren(HP, avatar);

            this.setup();
        }
        _proto.setup = function () {
            this.centerX = 0;
            this.y = 45;
        }
        _proto.update = function (data) {
            this.HP.update(data.hp);
        }
    })(Laya.Box);
})();